Rotate an array of n elements to the right by k steps. Problem from LeetCode
In [50]:
# Input
n = [1,2]
k = 1
In [51]:
def rotate(nums, k):
k = k % len(nums)
nums[:] = nums[-k:] + nums[:-k]
In [52]:
# Function call
rotate(n, k)
In [53]:
# Print results
print (n)